import request from "@/request";
import type { responseType } from "./interface";
import axios from "axios";

const prefix = "/groupEntity";

// 参数接口
export interface UpdateTeamParams {
  id?: number;
  acc?: string;
  leader?: string;
  name?: string;
  projectName?: string;
  createBy?: string;
  createTime?: Record<string, unknown>;
  updateBy?: string;
  updateTime?: Record<string, unknown>;
  undock?: number;
  state?: number;
  remark?: string;
}

export function updateTeam(params: UpdateTeamParams): Promise<responseType> {
  return request.post(`${prefix}/update`, params);
}

/**
 * 查询-名称
 * @param {string} param
 * @returns
 */
export function selectTeamByName(param: string): Promise<responseType> {
  return request.post(`${prefix}/selectGroupByName/${param}`);
}

/**
 * 查询-编号
 * @param {string} param
 * @returns
 */
export function selectTeamByID(param: string): Promise<responseType> {
  return request.post(`${prefix}/selectGroupByID/${param}`);
}

/**
 * 列表-分页
 * @param {string} page
 * @param {string} pageSize
 * @returns
 */
export function listPageTeam(
  page: number,
  pageSize: number
): Promise<responseType> {
  return request.post(
    `${prefix}/listPageGroup?page=${page}&pageSize=${pageSize}`
  );
}

/**
 * 导出功能
 * @param param
 */
export function exportExcel(param: string) {
  return request.post(
    `${prefix}/export/${param}`,
    {},
    {
      responseType: "blob",
    }
  );
}

// 参数接口
export interface InsertGroupParams {
  id?: number;
  acc?: string;
  leader?: string;
  name?: string;
  projectName?: string;
  createBy?: string;
  createTime?: Record<string, unknown>;
  updateBy?: string;
  updateTime?: Record<string, unknown>;
  undock?: number;
  state?: number;
  remark?: string;
}

/**
 * 保存
 * @param {object} params $!{table.comment}
 * @returns
 */
export function insertTeam(params: InsertGroupParams): Promise<responseType> {
  return request.post(`${prefix}/insert`, params);
}

/**
 * 删除
 * @param {string} param
 * @returns
 */
export function deleteTeam(param: string): Promise<responseType> {
  return request.post(`${prefix}/delete/${param}`);
}
